// miniprogram/pages/select/select.js
const { weekHot } = require('../../utils/week-hot')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    placholderValue: '',
    weekHotList: [],
    timeFreeList: [],
    clientHeight: ''
  },
  search: function () {
    wx.navigateTo({
      url: '../search/search?value=' + this.data.placholderValue
    })
  },
  getMoreClick: function() {
    wx.navigateTo({
      url: '../more/more'
    })
  },
  detailClick: function(e) {
    let id = e.currentTarget.dataset['id']
    wx.navigateTo({
      url: '../detail/detail?id=' + id
    })
  },
  tradeClick: function() {
    this.data.timeFreeList = []
    let Arr = [];
    let arr = []
    // 声明一个变量并赋值
    let add = 0;
    while(add < 3){
      let num= Math.floor(10 * Math.random())
      if(arr.indexOf(num) === -1){
        arr.push(num)
        Arr.push(weekHot[num]);
        add++;
      }
    }
    this.setData({
      timeFreeList: Arr
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    let arr = weekHot.slice(0, 4)
    let timeFree = weekHot.slice(0,3)
    wx.getSystemInfo({ 
      success: function (res) {
        that.setData({ 
              clientHeight: res.windowHeight - 20,
              weekHotList: arr,
              timeFreeList: timeFree
          })
      } 
  })
    // this.setData({
    //   weekHotList: arr,
    //   timeFreeList: timeFree,
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let searchArray = ['遮天', '剑来', '完美世界', '诡秘之主', '善良的死神', '执魔', '从姑获鸟开始', '神墓', '全球高武', '雪中悍刀行']
    let searchIndex = Math.floor(Math.random() * 10)
    this.setData({
      placholderValue: searchArray[searchIndex]
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})